package com.boot.test;

import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.Single;

import java.util.concurrent.TimeUnit;

public class RxJavaSingle {
    public static void main(String[] args){
        Single.create(singleEmitter -> singleEmitter.onSuccess("Hello world!"))
                .subscribe(System.out::println, error -> error.printStackTrace());
        Completable.fromAction(() -> System.out.println("Hello world!")).subscribe();
        Completable.create(completableEmitter  -> {
            try {
                TimeUnit.SECONDS.sleep(1);
                completableEmitter.onComplete();
            }catch (Exception e){
                completableEmitter.onError(e);
            }
        }).andThen(Observable.range(1, 10))
                .subscribe(System.out::println);
        Maybe.create(maybeEmitter -> {
            maybeEmitter.onComplete();
            maybeEmitter.onSuccess("hello world1");
            maybeEmitter.onSuccess("hello world2");
        }).subscribe(System.out::println, error -> error.printStackTrace(), () -> System.out.println("Complete"));;
    }
}
